package com.station.client.proxies;


import com.google.gwt.user.client.ui.Label;
import com.station.client.Base;
import com.station.client.Listener;

import java.util.ArrayList;
import java.util.List;

/**
 * User: JinJavaMojo
 * Date: 25.09.13
 */
public class PFuelTank extends PPlaceableEntity {

    private double maxCapacity;
    private double currentCapacity;
    public String fuel;
    private List<PPetrolPump> pumps;
    private PStation stationId;
    private transient List<Listener> listeners;

    private transient Label currentCapacityLabel;

    public PFuelTank() {

    }

    public PFuelTank(String fuel,double maxCapacity,double currentCapacity) {
        this.maxCapacity = maxCapacity;
        this.currentCapacity = currentCapacity;
        this.fuel = fuel;
        listeners = new ArrayList<Listener>();
    }

    public PFuelTank(PCoordinates coordinates){
        this.pCoordinates = coordinates;

    }

    public void decreaseFuel(Double value) {
        currentCapacity -=value;
        refreshDisplay();
        if (isEmpty())
            notifyListeners();
    }

    public double getCurrentCapacity() {
        return currentCapacity;
    }

    public void setCurrentCapacity(double currentCapacity) {
        this.currentCapacity = currentCapacity;
    }

    public double getMaxCapacity() {
        return maxCapacity;
    }

    public void setMaxCapacity(double maxCapacity) {
        this.maxCapacity = maxCapacity;
    }

    public PStation getStationId() {
        return stationId;
    }

    public void setStationId(PStation stationOwner) {
        this.stationId = stationOwner;
    }

    public List<PPetrolPump> getPumps() {
        return pumps;
    }

    public void setPumps(List<PPetrolPump> pumps) {
        this.pumps = pumps;
    }

    public boolean isEmpty() {
        return currentCapacity < Base.fillingSpeed;
    }

    public boolean isFillUp() {
        return currentCapacity >= maxCapacity;
    }

    public void initDisplay(Label currentCapacity) {
        currentCapacityLabel = currentCapacity;
        refreshDisplay();

    }

    public void refreshDisplay() {
        currentCapacityLabel.setText(String.valueOf(currentCapacity + "/" + maxCapacity));
    }

    public void addListener(Listener l) {
        listeners.add(l);
    }

    public void notifyListeners() {
        for (Listener l : listeners)
            l.fireRefuellerEvent(fuel);
    }

    public void fillUp(double value) {
        currentCapacity+=value;
        refreshDisplay();
    }
}
